package com.guli.gulimall.product.web.controller;

import com.guli.gulimall.product.entity.CategoryEntity;
import com.guli.gulimall.product.service.CategoryService;
import com.guli.gulimall.product.service.SkuInfoService;
import com.guli.gulimall.product.vo.Catalog2Vo;
import com.guli.gulimall.product.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

/**
 * @author 武者
 * @title: IndexController
 * @projectName gulimall-zhuan5
 * @description:
 * @date 2022/1/5 9:16
 */
@Controller
public class IndexController {

    @Autowired
    SkuInfoService skuInfoService;

    @Autowired
    private CategoryService categoryService;

    @RequestMapping(path = {"/","/index.html"})
    public String index(Model model){

        List<CategoryEntity> list= categoryService.getCategotyLevelList();

        model.addAttribute("list",list);
        return "index.html";
    }
    @RequestMapping("findCatalog")
    @ResponseBody
    public Map<String,List<Catalog2Vo>> findCatalog(Model model){
        Map<String, List<Catalog2Vo>> catalog = categoryService.findCatalog();


        return catalog;
    }

    @RequestMapping("/{skuId}.html")
    public String item(@PathVariable Integer skuId,Model model) throws ExecutionException, InterruptedException {
        SkuItemVo vo = skuInfoService.getItemBySkuId(skuId);
        model.addAttribute("item",vo);


        return "item.html";
    }


}
